package com.jcgyl.export.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jcgyl.export.entity.Tbreceipt;
import com.jcgyl.export.entity.Tbwaybill;
import com.jcgyl.export.model.Receitp.ReceiptModel;
import com.jcgyl.export.model.order.OrderModel;
import com.jcgyl.export.model.waybill.WaybillModel;
import com.jcgyl.export.service.WaybillService;
import com.jcgyl.export.util.entity.JsonResult;
import com.jcgyl.export.util.entity.JsonUtil;
import com.jcgyl.export.util.entity.PageResult;

@Controller
@RequestMapping("/waybill")
public class WaybillController {
	@Autowired
	private WaybillService waybillService;
	@GetMapping("/query")
	public String Query() {
		return "waybill/query";
	}
	
	/**
	 * 根据条件查询数据
	 * @param waybillModel
	 * @return
	 * JL
	 */
	@RequestMapping("doFindObject")
	@ResponseBody
	public PageResult doFindObject(@RequestBody WaybillModel waybillModel) {
		// 获取前端输入的值
		int pageSize = waybillModel.getPageSize();
		int pageCount = waybillModel.getPageIndex();
		String orderid = waybillModel.getFilter().getOrderid();
		String batchnumber = waybillModel.getFilter().getBatchnumber();
		String expressnumber = waybillModel.getFilter().getExpressnumber();
		String Starttime = waybillModel.getFilter().getStart();
		String Endtime  = waybillModel.getFilter().getEnd();
		List<Tbwaybill>list = waybillService.findObject(orderid, batchnumber, expressnumber, Starttime,Endtime, pageSize, pageCount);
		int row = waybillService.getRowCount(orderid, batchnumber, expressnumber, Starttime,Endtime);
		PageResult jsonResult = new PageResult();
		jsonResult.setTotalRows(row);
		jsonResult.setResult(list);
		return jsonResult;
	}
	/**
	 * 修改运单信息
	 * @param tbwaybill
	 * @return
	 * JL
	 */
	@RequestMapping("doUpdateObject")
	@ResponseBody
	public JsonResult doUpdateObject(@RequestBody Tbwaybill tbwaybill) {
		int row = waybillService.UpdataObject(tbwaybill);
		if(row!=1){
			return JsonUtil.error(1,"修改运单失败");
		}else{
			return JsonUtil.success(row);
		}
		
	}
	/**
	 * 运单回执查询
	 * @param tbreceipt 
	 * @return
	 * JL
	 */
	@RequestMapping("doFindReceipt")
	@ResponseBody
	public JsonResult doFindReceipt(@RequestBody ReceiptModel tbreceipt){
		//运单回执码
		String receipttype = "IEPT401_BACK";
		//获取运单号
		String expressnumber = tbreceipt.getExpressNumber();
		List<Tbreceipt>list = waybillService.findReceipt(receipttype, expressnumber);
		if(list.size() == 0){
			return JsonUtil.error(1, "暂无运单报文信息！");
		}else{
			return JsonUtil.success(list);
		}
	}
}
